import { hello } from "./m1";

function sum(n1: number, n2: number): number {
  return n1 + n2
}

let count = sum(123, 456)

let box1 = document.getElementById("box1")

box1!.innerHTML = count.toString()


console.log('count :>> ', count.toString());

console.log('hello :>> ', hello.toString());


class Person {

  name: string = "孙悟空"

  age: number = 18

  sayHello() {
    console.log('hello sayHello :>> ', this.name, this.age);
  }

  toStr(): string {
    return this.name + this.age
  }

  static sayCall() {
    console.log('Call :>> sayCall');
  }

  readonly gender: number = 1

  static hello: string = "Hello World"
}

let p1 = new Person()
console.log('hello p1 :>> ', p1.name, p1.age);
console.log('Person.hello :>> ', Person.hello);

p1.name = "猪八戒"
p1.age = 28

console.log('hello p1 :>> ', p1.name, p1.age, p1.gender);

p1.sayHello()

console.log('p1.toStr() :>> ', p1.toStr());

Person.sayCall();


class Dog {

  name: string

  age: number

  constructor(name: string, age: number) {
    this.name = name
    this.age = age
  }

  call() {
    console.log('this. :>> ', this)
  }

}

let d1 = new Dog("旺财", 5)
d1.call()

let d2 = new Dog('小黑', 8)
d2.call()



class Animal {
  name: string
  age: number

  constructor(name: string, age: number) {
    this.name = name
    this.age = age
  }

  sayHello() {
    console.log(`${this.name} 在叫 :>> `);
  }

}


class Cat extends Animal {

  sayHello(): void {
    super.sayHello()
    console.log(`${this.name} 在 喵喵喵 的叫 :>> `);
  }

}


class Bird extends Animal {

  sayHello(): void {
    super.sayHello()
    console.log(`${this.name} 在 叽叽喳喳 的叫 :>> `);
  }

}


new Bird('小飞', 3).sayHello();

new Cat('tom', 2).sayHello();



abstract class Insect {
  name: string
  age: number

  constructor(name: string, age: number) {
    this.name = name
    this.age = age
  }

  abstract sayHello(): void

}



class Cricket extends Insect {

  sayHello(): void {
    console.log(`${this.name}  在叫 :>> `);
  }

}


new Cricket('小郭', 2).sayHello();


interface Upload {

  upload(): void

}


interface Download {

  download(): void

}


class AliOss implements Upload, Download {
  download(): void {
    console.log('AliOss Download :>> ');
  }

  upload(): void {
    console.log('AliOss Upload :>> ');
  }

}


let dow: Download = new AliOss()
dow.download()


let upl: Upload = new AliOss()
upl.upload()


class Company {
  private _name: string
  private _found: number

  constructor(name: string, found: number) {
    this._name = name
    this._found = found
  }

  public get name(): string {
    console.log('调用了 get name() :>> ');
    return this._name
  }

  public set name(v: string) {
    this._name = v;
  }

  public get found(): number {
    return this._found
  }

  public set found(v: number) {
    this._found = v;
  }

}

let tencent = new Company("腾讯", 24)

console.log('调用了 get name() :>> ', tencent.name);


class Enterprise {

  constructor(public name: string, public scale: number) {

  }

}

let jd = new Enterprise("京东", 200000)
console.log('调用了 Enterprise :>> ', jd);


// 泛型
interface Str {

  toString(): string

}

function fun<T extends Str>(params: T): string {
  return params.toString()
}

console.log('fun(\'123\') :>> ', fun('123'));

console.log('fun(123456) :>> ', fun(123456));


let map = new Map<string,number>();
map.values

